package com.hackathon.sgstern.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hackathon.sgstern.R;
import com.hackathon.sgstern.dataprovider.LogoProvider;
import com.hackathon.sgstern.model.Person;

public class PersonAdapter extends BaseAdapter {

	public List<Person> persons;
	LayoutInflater inflator;
	Context context;

	public PersonAdapter(Context context) {
		inflator = LayoutInflater.from(context);
		this.context = context;
		this.persons = persons;
	}

	@Override
	public int getCount() {
		return persons.size();
	}

	@Override
	public Object getItem(int position) {
		return persons.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Person person = persons.get(position);
		convertView = inflator.inflate(R.layout.list_item_person, null);
		TextView nickname = (TextView) convertView
				.findViewById(R.id.list_person_nickname);
		TextView costcenter = (TextView) convertView
				.findViewById(R.id.list_person_costcenter);
		ImageView image = (ImageView) convertView
				.findViewById(R.id.list_person_icon);
		Bitmap bitmap = LogoProvider.retrieveProfilePicure(context,
				person.nickname);
		image.setImageBitmap(bitmap);
		nickname.setText(person.nickname);
		costcenter.setText(person.costCenter);
		return convertView;
	}
}
